As part of the PhD work of Bruno M. Guerreiro © 2024. If using this notebook, please cite the paper: https://doi.org/10.1021/acsbiomaterials.2c00075
Disclaimer: due to the changing nature of programming documentation, lab work developed and tacit knowledge in this notebook, please contact the author at bruno.guerreiro@fulbrightmail.org if something is not working properly. The code is not actively maintained.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objs as go
import math
# retrieve sample data from stage 1
%store -r water
%store -r fp025
%store -r fp05
### SURVIVAL GRAPH CALCULATIONS
# Obtain y-axis: Order nucleation temperatures from smallest to largest
water_Tnuc = sorted(water['Tnuc'], reverse=False)
fp025_Tnuc = sorted(fp025['Tnuc'], reverse=False)
fp05_Tnuc = sorted(fp05['Tnuc'], reverse=False)
# Obtain x-axis: Divide index by length of array
chi_water = []
for i in range(0,len(water_Tnuc)):
chi_water.append((i+1)/len(water_Tnuc))
chi_fp025 = []
for i in range(0,len(fp025_Tnuc)):
chi_fp025.append((i+1)/len(fp025_Tnuc))
chi_fp05 = []
for i in range(0,len(fp05_Tnuc)):
chi_fp05.append((i+1)/len(fp05_Tnuc))
pd.Series(water_Tnuc).to_csv (r'data\INDe_cycles\water_UF.csv', index = False, header=True)
pd.Series(fp025_Tnuc).to_csv (r'data\INDe_cycles\fp025_UF.csv', index = False, header=True)
pd.Series(fp05_Tnuc).to_csv (r'data\INDe_cycles\fp05_UF.csv', index = False, header=True)
pd.Series(chi_water).to_csv (r'data\INDe_cycles\chi_water.csv', index = False, header=True)
pd.Series(chi_fp025).to_csv (r'data\INDe_cycles\chi_fp025.csv', index = False, header=True)
pd.Series(chi_fp05).to_csv (r'data\INDe_cycles\chi_fp05.csv', index = False, header=True)
%store water_Tnuc
%store fp025_Tnuc
%store fp05_Tnuc
%store chi_water
%store chi_fp025
%store chi_fp05
Stored 'water_Tnuc' (list) Stored 'fp025_Tnuc' (list) Stored 'fp05_Tnuc' (list) Stored 'chi_water' (list) Stored 'chi_fp025' (list) Stored 'chi_fp05' (list)
###### import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(rows=1, cols=3)
# Tnuc-cycle plot
fig.add_trace(go.Scatter(name='Water', x=water['Cycle'], y=water['Tnuc'], mode='lines+markers', legendgroup=1, marker_color='black'), row=1,col=1)
fig.add_trace(go.Scatter(name='0.25% FP', x=fp025['Cycle'], y=fp025['Tnuc'], mode='lines+markers', legendgroup=1, marker_color='blue'), row=1,col=2)
fig.add_trace(go.Scatter(name='0.5% FP (new)', x=fp05['Cycle'], y=fp05['Tnuc'], mode='lines+markers', legendgroup=1, marker_color='red'), row=1,col=3)
'''
# Survivor plot
fig.add_trace(go.Scatter(x=chi_water, y=water_Tnuc, mode='markers', marker_size=10, opacity=0.55, marker_color='blue', legendgroup=2), row=1,col=2)
fig.add_trace(go.Scatter(x=chi_fp025, y=fp025_Tnuc, mode='markers', marker_size=10, opacity=0.55, marker_color='orange', legendgroup=2), row=1,col=2)
fig.add_trace(go.Scatter(x=chi_fp05, y=fp05_Tnuc, mode='markers', marker_size=10, opacity=0.55, marker_color='red', legendgroup=2), row=1,col=2)
fig.add_trace(go.Scatter(x=chi_fp05_issues, y=fp05_issues_Tnuc, mode='markers', marker_size=10, opacity=0.55, marker_color='red', legendgroup=2), row=1,col=2)
#POISSON FIT HERE --- fig.add_trace(go.Scatter(x=chi, y=ordered_Tnuc, mode='lines', line_color='black', line_width=2, opacity=.35), row=1,col=3)
# Violin plot
fig.add_trace(go.Violin(y=water['Tnuc'], name='0', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, opacity=.75, marker_size=5, legendgroup=3), row=1, col=3)
fig.add_trace(go.Violin(y=fp025['Tnuc'], name='0.25', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, marker_size=5, legendgroup=3), row=1, col=3)
fig.add_trace(go.Violin(y=fp05['Tnuc'], name='0.5', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, marker_size=5, legendgroup=3), row=1, col=3)
fig.add_trace(go.Violin(y=fp05_issues['Tnuc'], name='0.5_issues', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, marker_size=5, legendgroup=3), row=1, col=3)
# Box plot
#fig.add_trace(go.Box(y=water['Tnuc'], boxpoints='all', pointpos=0, marker_color='rgb(107,174,214)', marker_opacity=.35, marker_size=8, line_color='rgb(107,174,214)', name="without", legendgroup=4), row=1, col=4)
#fig.add_trace(go.Box(y=sample['Tnuc'], boxpoints='all', pointpos=0, marker_opacity=.35, marker_size=8, name="with", legendgroup=4), row=1, col=4)
'''
relevantrange = [-15,0]
fig.update_layout(template='simple_white+gridon',
showlegend=False,
xaxis1_title = 'Pure water',
xaxis2_title = 'FucoPol 0.25 wt.%',
xaxis3_title = 'FucoPol 0.5 wt.%',
yaxis1_title = 'Nucleation temperature (ºC)',
yaxis1_range = relevantrange,
yaxis2_range = relevantrange,
yaxis3_range = relevantrange)
fig.show()
# Survivor plot
fig = go.Figure()
fig.add_trace(go.Scatter(name='Water', x=chi_water, y=water_Tnuc, mode='markers', marker_color='black', marker_symbol="100", legendgroup=2))
fig.add_trace(go.Scatter(name='FucoPol 0.25 wt.%', x=chi_fp025, y=fp025_Tnuc, mode='markers', marker_color='blue', marker_symbol="135", legendgroup=2))
fig.add_trace(go.Scatter(name='FucoPol 0.5 wt.%', x=chi_fp05, y=fp05_Tnuc, mode='markers', marker_color='red', marker_symbol="135", legendgroup=2))
fig.update_traces(mode='markers', marker_line_width=2, marker_size=5, opacity=.7)
fig.update_layout(template='simple_white+gridon',
width = 500,
height = 500,
showlegend=True,
xaxis_title = 'Unfrozen fraction (%)',
yaxis_title = 'Nucleation temperature (ºC)'
)
fig.show()
# Violin plot
fig = go.Figure()
fig.add_trace(go.Violin(y=water['Tnuc'], name='0', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, line_color='black', opacity=.75, marker_size=5, legendgroup=3))
fig.add_trace(go.Violin(y=fp025['Tnuc'], name='0.25', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, line_color='blue', marker_size=5, legendgroup=3))
fig.add_trace(go.Violin(y=fp05['Tnuc'], name='0.5', box_visible=True, points='all', meanline_visible=True, pointpos=0, marker_opacity=.35, line_color='red', marker_size=5, legendgroup=3))
fig.update_traces(marker_color='rgba(255,255,255,1)', marker_size=3, marker_symbol=100)
fig.update_layout(template='simple_white+gridon',
width = 500,
height = 500,
showlegend=True,
xaxis_title = 'FucoPol concentration (wt.%)',
yaxis_title = 'Nucleation temperature (ºC)'
)
fig.show()
paper = pd.DataFrame()
paper['Water'] = pd.Series(water['Tnuc'])
paper['0.25% FP'] = pd.Series(fp025['Tnuc'])
paper['0.5% FP'] = pd.Series(fp05['Tnuc'])
round(paper.describe(), 2)
| Water | 0.25% FP | 0.5% FP | |
|---|---|---|---|
| count | 304.00 | 304.00 | 154.00 |
| mean | -11.20 | -10.30 | -10.86 |
| std | 1.59 | 0.75 | 0.40 |
| min | -14.93 | -11.86 | -11.75 |
| 25% | -12.06 | -10.83 | -11.07 |
| 50% | -11.41 | -10.31 | -10.90 |
| 75% | -10.69 | -10.00 | -10.71 |
| max | 3.02 | -7.98 | -8.94 |
import plotly.graph_objects as go
import pandas as pd
fig = go.Figure()
fig.add_trace(go.Violin(y=paper['Water'], name=0, box_visible=True, meanline_visible=True,
#points='all',
pointpos=0, line_color='black',
marker_color='black', marker_opacity=.35, marker_size=8, jitter=.1, marker_symbol=100))
fig.add_trace(go.Violin(y=paper['0.25% FP'], name=0.25, box_visible=True, meanline_visible=True,
#points='all',
pointpos=0, line_color='blue',
marker_color='blue', marker_opacity=.5, marker_size=8, jitter=.1, marker_symbol=100))
fig.add_trace(go.Violin(y=paper['0.5% FP'], name=0.5, box_visible=True, meanline_visible=True,
#points='all',
pointpos=0, line_color='red',
marker_color='crimson', marker_opacity=.5, marker_size=8, jitter=.1, marker_symbol=100))
fig.update_layout(template='simple_white', width=350, height=500, showlegend=False,
xaxis_title='<b>FucoPol concentration (wt.%)<b>',
yaxis_title='<b>Nucleation temperature (ºC)<b>',
font_family='Arial', font_color='black', font_size=16)
fig.update_traces(width=.8)
fig.update_xaxes(mirror=True, showline=True, ticks='outside', linewidth=2, tickprefix="<b>",ticksuffix ="</b>")
fig.update_yaxes(mirror=True, showline=True, ticks='outside', linewidth=2, dtick=1, tickprefix="<b>",ticksuffix ="</b>")
fig.show()
#fig.write_image("images/violin_total.svg")
import csv
pd.Series(paper['Water']).to_csv('fig1_water_resub.csv')
pd.Series(paper['0.25% FP']).to_csv('fig1_025fp_resub.csv')
pd.Series(paper['0.5% FP']).to_csv('fig1_05fp_resub.csv')
import plotly.graph_objects as go
import pandas as pd
fig = go.Figure()
fig.add_trace(go.Violin(y=paper['0.5% FP'], name='global', box_visible=True, meanline_visible=True,
points='all', pointpos=0, line_color='gray',
marker_color='crimson', marker_opacity=.5, marker_size=8, jitter=.5, marker_symbol=100))
#1-72
fig.add_trace(go.Violin(y=paper[paper['0.5% FP'] > -11]['0.5% FP'], name='segmented', box_visible=True, meanline_visible=False,
points='outliers', pointpos=0, width=.5,
line_color='crimson',
marker_color='crimson', opacity=1, marker_size=8, jitter=.5, marker_symbol=100))
#75-154
fig.add_trace(go.Violin(y=paper[paper['0.5% FP'] < -11]['0.5% FP'], name='segmented', box_visible=True, meanline_visible=False,
points='outliers', pointpos=0, width=.5,
line_color='#778899',
marker_color='#778899', opacity=1, marker_size=8, jitter=.5, marker_symbol=100))
fig.update_layout(template='simple_white', width=350, height=500, showlegend=False,
#xaxis_title='<b>0.25% FucoPol<b>',
yaxis_title='<b>Nucleation temperature (ºC)<b>',
uniformtext_minsize=20,
font_family='Arial', font_color='black', font_size=16)
#fig.update_xaxes(mirror=True, showline=True, ticks='outside', linewidth=2)
#fig.update_yaxes(mirror=True, showline=True, ticks='outside', linewidth=2, dtick=1)
fig.update_xaxes(mirror=True, showline=True, ticks='outside', linewidth=2, tickprefix="<b>",ticksuffix ="</b>", range=[-0.5,1.5])
fig.update_yaxes(mirror=True, showline=True, ticks='outside', linewidth=2, dtick=.5, tickprefix="<b>",ticksuffix ="</b>")
fig.show()